import getlist from '../../netwoky/index'
const Classify = {
    state: {
        categorylist: [],
        showcategorylist: [],
        sliderleft: []
    },
    mutations:{
        getCategory(state, item){
            state.categorylist = item;
            state.showcategorylist = item;
            state.sliderleft = []
            state.categorylist.forEach((ele =>{
                if (ele.pid === 0){
                    state.sliderleft.push(ele)
                }
            }))
            console.log(state.sliderleft)
        },
        changecurrent(state, item){
            state.showcategorylist =[];
            state.categorylist.forEach((ele)=>{
                if (ele.type.includes(item.type)){
                    state.showcategorylist.push(ele)
                }
            })
            // console.log(state.showcategorylist)
        },
        allclick(state){
            state.showcategorylist = state.categorylist
        }
    },
    actions:{
        // 分类列表数据
        getCategory(context) {
            getlist.Category({}).then((resp) => {
                // console.log(resp.data.data)
                
                context.commit("getCategory", resp.data.data)
            }).catch((error) => {
                console.log(error)
            })
        },
        // 更改分类内容
        changecurrent(context, item) {
            // console.log(item)
            context.commit("changecurrent", item)
        },
        allclick(context) {
            context.commit("allclick")
        }
    },
    modules: {

    }
}
export default Classify